package com.powergisol.gis.geom;

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import org.geotools.geojson.geom.GeometryJSON;
import org.geotools.geometry.jts.JTSFactoryFinder;

import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Map;
import java.util.Properties;

public abstract class GeoType {

    protected GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();


    protected Properties properties = new Properties();

    /**
     *
     * @return
     */
    public String toJSON() {

        Writer writer = new StringWriter();
        try {
            new GeometryJSON(8).write(toGeometry(),writer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return writer.toString();
    }

    /**
     *
     * @param <T>
     * @return
     */
    public  abstract <T extends Geometry> T toGeometry();

    /**
     * to WKT(Well-known text) message
     * @return
     */
    public abstract String toWKT();

    public void setProperties(Map<String,Object> properties){
        this.properties.putAll(properties);
    }

    public Properties getProperties() {
        return properties;
    }
}
